<?php if (!defined('BASEPATH')) exit('No direct script access allowed');



class Usuario extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        // Carrega model
        $this->load->model('admin/usuario_model');
        $data = array(
            'title_for_layout' => 'Administra&ccedil;&atilde;o | Usu&aacute;rio',
            'title_for_page'   => 'Listagem de Usu&aacute;rio',
            'filiacoes'        => $this->usuario_model->listar(),
            'content_layout'   => 'admin/modulos/usuario/usuario'
        );
        $this->parser->parse('admin/layout_main',$data);
    }

    public function cadastro(){
        $data = array(
            'title_for_layout' => 'Administra&ccedil;&atilde;o | Usu&aacute;rio',
            'content_layout'   => 'admin/modulos/usuario/cadastrar'
        );
        $this->parser->parse('admin/layout_main',$data);
    }
    public function adicionar()
    {
        $config = array(
            array(
                'field' => 'pai',
                'label' => 'Pai',
                'rules' => 'required|min_length[4]|max_length[20]'
            ),
            array(
                'field' => 'mae',
                'label' => 'Mae',
                'rules' => 'required|min_length[4]|max_length[20]'
            )
        );
        $this->form_validation->set_rules( $config );
        if ( $this->form_validation->run() == FALSE )
        {
            $this->index();
        }
        else
        {
            $data['pai'] = $this->input->post('pai');
            $data['mae'] = $this->input->post('mae');

            $this->load->model('admin/filiacao_model');

            if ($this->filiacao_model->cadastrar($data)) {
                $this->index();
            }
            else
            {
              echo 'Erro ao inserir a filiacao';
            }
        }
    }
}